package com.fast.common.service.impl;

import com.baomidou.mybatisplus.core.conditions.AbstractWrapper;
import com.baomidou.mybatisplus.core.conditions.SharedString;
import com.baomidou.mybatisplus.core.conditions.query.Query;
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
import com.baomidou.mybatisplus.core.toolkit.ArrayUtils;
import com.fast.common.service.IBaseService;
import lombok.SneakyThrows;

import java.util.function.Predicate;

/**
 * Class FastQueryWrapper
 *
 * @Auther: lhy
 * @Date: 2021/11/25 11:33
 * @Mail: 190643201@qq.com
 */
public class FastWrapper<T> extends AbstractWrapper<T, String, FastWrapper<T>> implements Query<FastWrapper<T>, T, String> {

    private final IBaseService<T> iBaseService;
    private final SharedString sqlSelect;

    public FastWrapper(IBaseService<T> iBaseService) {
        this.sqlSelect = new SharedString();
        this.iBaseService = iBaseService;
        super.initNeed();
    }

    public IBaseService<T> end(String sql) {
        last(sql);
        return iBaseService;
    }

    @SneakyThrows
    public IBaseService<T> end() {
        return iBaseService;
    }


    public FastWrapper<T> select(String... columns) {
        if (ArrayUtils.isNotEmpty(columns)) {
            this.sqlSelect.setStringValue(String.join(",", columns));
        }
        return this;
    }

    public FastWrapper<T> select(){
        return this;
    }

    @Override
    public FastWrapper<T> select(Class<T> entityClass, Predicate<TableFieldInfo> predicate) {
        return null;
    }


    public String getSqlSelect() {
        return this.sqlSelect.getStringValue();
    }

    @Override
    protected FastWrapper<T> instance() {
        return null;
    }

    public void clear() {
        super.clear();
        this.sqlSelect.toNull();
    }
}
